using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace PengYouClient
{
    public class pengyouUtils
    {
        public static bool GetWordDocumentProp(Word._Application app, string propName, out string prop)
        {
            prop = null;
            if (app.Documents.Count == 0)
                return false;
            object customPropertiesObject = app.ActiveDocument.CustomDocumentProperties;
            Microsoft.Office.Core.DocumentProperties properties = 
                (Microsoft.Office.Core.DocumentProperties)customPropertiesObject;
            IEnumerator dicenum = properties.GetEnumerator();
            while (dicenum.MoveNext())
            {
                Microsoft.Office.Core.DocumentProperty property = (Microsoft.Office.Core.DocumentProperty)dicenum.Current;
                string name = property.Name.ToString();
                string value = property.Value.ToString();
                if (name == propName)
                {
                    prop = value;
                    return true;
                }
            }

            return false;
        }
    }

    public class DateDiff
    {
        string diff;

        public string Diff
        {
            get
            {
                return diff;
            }

            set
            {
                diff = value;
            }
        }

        public DateDiff(DateTime first, DateTime second)
        {
            TimeSpan n = first.Subtract(second);

            if (n.Days > 31)
                diff += n.Days / 31 + " month";
            else if (n.Days > 7 && n.Days % 7 != 1)
                diff += n.Days / 7 + " weeks";
            else if (n.Days > 7)
                diff += n.Days / 7 + " week";
            else if (n.Days > 0 && n.Days != 1)
                diff += n.Days + " days";
            else if (n.Days > 0)
                diff += n.Days + " day";
            else if (n.Days == 0 && n.Hours > 0 && n.Hours != 1)
                diff += n.Hours + " hours";
            else if (n.Days == 0 && n.Hours > 0)
                diff += n.Hours + " hour";
            else if (n.Minutes > 0 && n.Minutes != 1)
                diff += n.Minutes + " minutes";
            else if (n.Minutes > 0)
                diff += n.Minutes + " minute";
            else
                diff += n.Seconds + " seconds";
        }
    }
}
